public class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
}

class Solution {
    //解法1：双指针法
    public ListNode getKthFromEnd(ListNode head, int k) {
        if (head == null) return null;
        if (head.next == null) return head;
        ListNode slow = head;
        ListNode fast = head;
        for (int i = 0; i < k; i++) {
            fast = fast.next;
        }
        while (fast != null) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }
    //解法2：顺序查找，遍历链表求链表长度n，倒数第K个节点即是正数第n-k个节点 有点简单就不写了
}